<?php
    header("content-type:text/html;charset=utf-8");
    $username = $_POST['username'];
    $password = $_POST['password'];
    $link = mysql_connect('localhost', 'root', 'root') or die('数据链接失败');
    mysql_select_db('xiaomi', $link);
    $sql = "select * from `user` where `name` ='$username' and `password` = '$password'";
    $res = mysql_query($sql);
     // 匹配就是$row就是一个resource
     // 匹配不上$row返回就是false boolean
    $arr = [];
    if($res && $row = mysql_fetch_assoc($res)){
        $arr['code'] = 1;
        $arr['msg'] = '登陆成功';
        $arr['userid'] = (int)$row['id']; 
    }else{
        $arr['code'] = 0;
        $arr['msg'] = '登陆失败，用户名密码不存在';
    }
    echo json_encode($arr);
?>